<?php

require_once '../mvc/evento.php';

class Calendario {
// 	private $int_id;
// 	private $mysql_connection;
	private $evento;

	function __construct() {
// 		$this->mysql_connection =& $GLOBALS['mysql_connection'];
// 		$this->int_id = $int_id;
		$this->evento = new Evento();
	}

	function insert( $nombre, $int_id) {
		$query = sprintf( "INSERT INTO Calendario (Cal_nombre, Op_id) VALUES ( '%s', '%s')", $nombre, $int_id);
		if( ! $GLOBALS['mysql_connection']->query( $query)) return false;
		return true;
	}

// 	function get_calendarios() {
// 		$query = sprintf( "SELECT * FROM Calendario WHERE Op_id = '%s';", $this->int_id);
// 		
// 		if( !$result = $GLOBALS['mysql_connection']->query( $query)) return NULL;
// 		
// 		if( $result->num_rows == 0) return NULL;
// 
// 		$calendarios = array();
// 
// 		while( $row = $result->fetch_array()) {
// 			$calendarios[] = $row;
// 		}
// 		return $calendarios;
// 	}

	function get_calendarios( $int_id) {
		$query = sprintf( "SELECT Cal_id, Cal_nombre FROM Calendario WHERE Op_id = '%s';", $int_id);
		
		if( !$result = $GLOBALS['mysql_connection']->query( $query)) return NULL;
		
		if( $result->num_rows == 0) return NULL;

		$calendarios = array();

		while( $row = $result->fetch_array(MYSQLI_NUM)) {
			$calendarios[] = $row;
		}
		return $calendarios;
	}

	function add_evento( $evento) {
		return $this->evento->insert( $evento);
	}

	function get_eventos( $sem, $usu_id) {
		return $this->evento->get_eventos( $sem, $usu_id);
	}

	function get_tareas( $usu_id) {
		return $this->evento->get_tareas( $usu_id);
	}
}

?> 
